package com.fr.funglisoftproduction.flanders.database;

import java.util.Date;

import android.content.Context;

public class SpManager
{
	private static final String SP_NAME = "noob";
	
	public static void Put(Context contexte, String key, Object value)
	{
		Class<?> classe = value.getClass();
		
		if (classe.equals(String.class))
			contexte.getSharedPreferences(SP_NAME, 0).edit().putString(key, (String)value).commit();
		else if (classe.equals(Date.class))
			contexte.getSharedPreferences(SP_NAME, 0).edit().putLong(key, ((Date)value).getTime()).commit();
		else if (classe.equals(int.class) || classe.equals(Integer.class))
			contexte.getSharedPreferences(SP_NAME, 0).edit().putInt(key, (Integer)value).commit();
		else if (classe.equals(boolean.class) || classe.equals(Boolean.class))
			contexte.getSharedPreferences(SP_NAME, 0).edit().putBoolean(key, (Boolean)value).commit();
		else if (classe.equals(long.class) || classe.equals(Long.class))
			contexte.getSharedPreferences(SP_NAME, 0).edit().putLong(key, (Long)value).commit();
	}
	
	public static String GetString(Context contexte, String key)
	{
		return contexte.getSharedPreferences(SP_NAME, 0).getString(key, "");
	}
	
	public static Date GetDate(Context contexte, String key)
	{
		return new Date(contexte.getSharedPreferences(SP_NAME, 0).getLong(key, 0));
	}
	
	public static int GetInt(Context contexte, String key)
	{
		return contexte.getSharedPreferences(SP_NAME, 0).getInt(key, 0);
	}
	
	public static boolean GetBoolean(Context contexte, String key)
	{
		return contexte.getSharedPreferences(SP_NAME, 0).getBoolean(key, false);
	}
	
	public static long GetLong(Context contexte, String key)
	{
		return contexte.getSharedPreferences(SP_NAME, 0).getLong(key, 0);
	}
}
